library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ------------------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(gganimate)




data <- read_csv("../sgene_dropout_data/data.csv")
## Parsed with column specification:
## cols(
##   week_specimen = col_date(format = ""),
##   nhser_name = col_character(),
##   utla_name = col_character(),
##   utla_code = col_character(),
##   week_infection = col_date(format = ""),
##   prop_sgtf = col_double(),
##   samples = col_double()
## )
geo <- read_sf("./Counties_and_Unitary_Authorities__April_2019__Boundaries_EW_BUC-shp/Counties_and_Unitary_Authorities__April_2019__Boundaries_EW_BUC.shp")




both<- inner_join(geo,data,by=c("CTYUA19NM"="utla_name")) %>% filter(week_specimen>lubridate::ymd("2020-11-1"))

a<-ggplot(both,aes(fill=prop_sgtf))+geom_sf()+scale_fill_viridis_c(option='magma',direction=-1,limits=c(0,1))+theme_minimal()+transition_time(week_specimen)+labs(title="Date: {frame_time}",fill="SGTF")


animate(a,nframes=100,height=600,width=600,fps=10,end_pause = 20)

anim_save('uksgtf.gif')